package com.yugao.fintech.draper.oss.client.local;

import cn.hutool.core.io.FileUtil;
import com.yugao.fintech.draper.oss.propertie.FileStorageProperties;
import lombok.RequiredArgsConstructor;

/**
 * 本地文件存储
 */
@RequiredArgsConstructor
public class LocalFileStorage {

	private final FileStorageProperties properties;

	public String putObject(byte[] content, String path) {
		String filePath = getFilePath(path);
		FileUtil.writeBytes(content, filePath);
		return filePath;
	}

	public void delete(String path) {
		String filePath = getFilePath(path);
		FileUtil.del(filePath);
	}

	public byte[] getContent(String path) {
		String filePath = getFilePath(path);
		return FileUtil.readBytes(filePath);
	}

	private String getFilePath(String path) {
		return properties.getLocal().getBasePath() + path;
	}

}
